# Author:lzhan  Date:2020/3/16
import requests
import random
# 搜索的目的地
url='http://search.jumei.com/?'

condition={
    "filter":"0-11-1",
    "search":"香水"
}
browers = [
    {"name":"Chrome on windows","User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36"},
    {"name":"Chrome on iphone","User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/27.0.1453.10 Mobile/10B350 Safari/8536.25"},
    {"name":"Chrome on mac","User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36"},
    {"name":"Chrome on ubantu","User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko)Ubuntu/11.10 Chromium/27.0.1453.93 Chrome/27.0.1453.93 Safari/537.36"},
    {"name":"Chrome on android mobile","User-Agent": "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"}
]
for i in range(1,4):
    condition["filter"]=f'0-11-{i}'
    # 发送请求的主体
    # 伪装成浏览器
    my_headers = {"User-Agent": random.choice(browers)["User-Agent"]}
    response = requests.get(url, params=condition, headers=my_headers)
    html=response.text
    with open(f'data/pages/jumei_perfume_0{i}.html','w') as fp:
        fp.write(html)
        print(f"{i} 页爬取成功")






